#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1005;

int n, m, D;
char a[N][N];
int dis[N][N];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> D;
  rep(i, 1, n) rep(j, 1, m) cin >> a[i][j];

  int ans = 0;
  rep(i, 1, n) rep(j, 1, m) dis[i][j] = 1e9;
  queue<pii> q;
  rep(i, 1, n) rep(j, 1, m) if (a[i][j] == 'H') q.push(pii(i, j)),
      dis[i][j] = 0;
  while (q.size()) {
    pii now = q.front();
    q.pop();
    ans++;
    int x = now.first, y = now.second;
    int d = dis[x][y];
    if (d >= D) continue;
    rep(k, 0, 3) {
      int nx = x + dx[k], ny = y + dy[k];
      if (a[nx][ny] != '#' && dis[nx][ny] > d + 1) {
        dis[nx][ny] = d + 1;
        q.push(pii(nx, ny));
      }
    }
  }
  cout << ans;
  return 0;
}